package com.power.sifa.approve.model.enumeration;

import cn.hutool.core.collection.CollectionUtil;
import lombok.Getter;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @ClassName Tp_proctypeDocEnum
 * @Author xiongzw
 * @Date 2023/11/29 14:51
 * @Description 文书类型新增
 * @Version: 1.0
 **/

@Getter
public enum Tp_proctypeDocEnum {

    /********************************受理环节********************************************/
    ACCEPT_INFORM(Tp_proctype.ACCEPT_INFORM, "告知", Collections.emptyList(), Arrays.asList(Tp_procmaterialEnum.ARRIVE_INFORM)),

    ACCEPT_ACCEPT(Tp_proctype.ACCEPT_ACCEPT, "受理", Collections.emptyList(),Arrays.asList(Tp_procmaterialEnum.ADMRE_ACCEPT,
            Tp_procmaterialEnum.ADMRE_REPLY)),

    ACCEPT_APPEND(Tp_proctype.ACCEPT_APPEND, "补正",Collections.emptyList(), Arrays.asList(Tp_procmaterialEnum.ADMRE_APPEND)),

    ACCEPT_NOACCEPT(Tp_proctype.ACCEPT_NOACCEPT, "不予受理", Collections.emptyList(),Arrays.asList(Tp_procmaterialEnum.ADMRE_NOACCEPT)),

    ACCEPT_OTHERDEAL(Tp_proctype.ACCEPT_OTHERDEAL, "视为放弃", Collections.emptyList(), Collections.emptyList()),


    /********************************审理环节********************************************/

    HEAR_HEARING(Tp_proctype.HEAR_HEARING, "听证",Collections.emptyList(), Arrays.asList(Tp_procmaterialEnum.HEAR_HEARING)),

    HEAR_STOP(Tp_proctype.HEAR_STOP, "停止执行",Collections.emptyList(), Arrays.asList(Tp_procmaterialEnum.HEAR_STOP)),


    HEAR_DELAY(Tp_proctype.HEAR_DELAY, "延期", Collections.emptyList(),Arrays.asList(Tp_procmaterialEnum.HEAR_DELAY)),

    HEAR_RESTORE(Tp_proctype.HEAR_RESTORE, "恢复", Collections.emptyList(),Arrays.asList(Tp_procmaterialEnum.HEAR_RESTORE)),

    HEAR_REST(Tp_proctype.HEAR_REST, "中止",Collections.emptyList(), Arrays.asList(Tp_procmaterialEnum.HEAR_HANGUP)),

    HEAR_DECISION_TERMIN(Tp_proctype.HEAR_DECISION, "决定-终止-其它", Arrays.asList(Tp_decision.TEROTHER),
            Arrays.asList(Tp_procmaterialEnum.HEAR_TERMIN)),

    HEAR_DECISION_REJECT(Tp_proctype.HEAR_DECISION, "决定-驳回", Arrays.asList( Tp_decision.PROREJECT,
            Tp_decision.SUBREJECT), Arrays.asList(Tp_procmaterialEnum.HEAR_REJECT)),

    HEAR_DECISION_DECISION(Tp_proctype.HEAR_DECISION, "决定-决定执行", Arrays.asList(Tp_decision.MAINTAIN,
            Tp_decision.BREAKLAW, Tp_decision.CHANGE, Tp_decision.ORDER),
            Arrays.asList(Tp_procmaterialEnum.HEAR_DECISION)),


    /********************************决定环节********************************************/

    EXECUTE_SELF(Tp_proctype.EXECUTE_SELF, "自行履行", Collections.emptyList(),Collections.emptyList()),


    EXECUTE_PERFORM(Tp_proctype.EXECUTE_PERFORM, "责令履行", Collections.emptyList(),Collections.emptyList()),

    EXECUTE_FORCE_UNIT(Tp_proctype.EXECUTE_FORCE_UNIT, "复议机关强制执行", Collections.emptyList(),Collections.emptyList()),

    EXECUTE_FORCE_LAW(Tp_proctype.EXECUTE_FORCE_LAW, "委托人民法院强制执行", Collections.emptyList(),Collections.emptyList());

    /**
     * 值
     */
    private Integer key;
    /**
     * 名称
     */
    private String name;

    /**
     * 决定类型
     */
    private List<Integer> decisionType;

    /**
     * 类型
     */
    private List<Tp_procmaterialEnum> procmaterials;


    Tp_proctypeDocEnum(Integer key, String name, List<Integer> decisionType, List<Tp_procmaterialEnum> procmaterials) {
        this.key = key;
        this.name = name;
        this.decisionType = decisionType;
        this.procmaterials = procmaterials;
    }


    public static Tp_proctypeDocEnum getByKey(Integer key) {
        Tp_proctypeDocEnum[] docEnum = Tp_proctypeDocEnum.values();
        for (Tp_proctypeDocEnum doc : docEnum) {
            if (doc.key.equals(key)) {
                return doc;
            }
        }
        return null;
    }


    public static Tp_proctypeDocEnum getByDecisionType(Integer decisionType) {
        Tp_proctypeDocEnum[] docEnum = Tp_proctypeDocEnum.values();
        for (Tp_proctypeDocEnum doc : docEnum) {
            if(CollectionUtil.isNotEmpty(doc.getDecisionType())) {
                if (doc.getDecisionType().stream().filter(element -> element.equals(decisionType)).findAny().isPresent()) {
                    return doc;
                }
            }
        }
        return null;
    }


}
